package com.example.myfr.adatper;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.myfr.R;
import com.example.myfr.model.Listitem;

import java.util.List;

public class Card1listAdapter extends RecyclerView.Adapter<Card1listAdapter.MyViewHolder> {
private  List<Listitem> mData;
private Context mContext;
    RequestOptions options;

    public Card1listAdapter(Context context, List<Listitem> data){
        this.mContext=context;
        this.mData=data;
        options = new RequestOptions().centerCrop().placeholder(R.drawable.ic_launcher_background).error(R.drawable.ic_launcher_background);
        this.notifyDataSetChanged();
    }
    @NonNull
    @Override
    public Card1listAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view;
        LayoutInflater inflater=LayoutInflater.from(mContext);
        view=inflater.inflate(R.layout.list_item,parent,false);
        MyViewHolder viewHolder=new MyViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        holder.tv_name.setText(mData.get(position).getName());
        holder.tv_rating.setText(mData.get(position).getRating());
        holder.tv_studio.setText(mData.get(position).getStudio());
        holder.tv_category.setText(mData.get(position).getCaetgoire());
        Glide.with(mContext).load(mData.get(position).getImg_url()).apply(options).into(holder.img_thumbnail);
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }
    public static  class MyViewHolder extends RecyclerView.ViewHolder{
        TextView tv_name;
        TextView tv_rating;
        TextView tv_studio;
        TextView tv_category;
        ImageView img_thumbnail;
        LinearLayout view_contain;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            view_contain=itemView.findViewById(R.id.container);
            tv_name=itemView.findViewById(R.id.item_namae);
            tv_rating=itemView.findViewById(R.id.rating);
            tv_studio=itemView.findViewById(R.id.studio);
            tv_category=itemView.findViewById(R.id.category);
            img_thumbnail=itemView.findViewById(R.id.thembnail);
        }
    }
}
